package video.dali.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import video.dali.common.dto.UserVideo;
import video.dali.common.entity.Video;

import java.util.List;

@Mapper
public interface VideoMapper {
    /**
     * 获取userId所有文件
     * @return
     */
    @Select("select * from video where user_id = #{userId}")
    List<Video> getByUserId(int userId);


    /**
     * 插入文件
     * @param video
     */
    void insert(Video video);


    /**
     * 删除用户视频
     * @param userVideo
     */
    @Delete("delete from video where id = #{id} and user_id = #{userId}")
    void deleteByIdAndUserId(UserVideo userVideo);

    /**
     * 查询所有视频
     * @param
     * @return
     */
    @Select("select * from video ;")
    List<Video> selectAll();


    /**
     * 根据id查询视频
     * @return
     */
    @Select("select * from video where id = #{id}")
    Video getById(Integer id);


    /**
     * 根据分类id查询视频
     * @param categoryId
     * @return
     */
    @Select("select * from video where category_id = #{categoryId}")
    Page<Video> getVideosByCategoryId(int categoryId);
}
